<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Bayesian Network: bayesian/make_sample.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Bayesian Network
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_4922399365a46b010edf8e4eee2a5dfb.html">bayesian</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">make_sample.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="make__sample_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef BAYESIAN_NETWORKS_MAKE_SAMPLE_HPP</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define BAYESIAN_NETWORKS_MAKE_SAMPLE_HPP</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;random&gt;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="network_8hpp.html">bayesian/network.hpp</a>&gt;</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="cpt_8hpp.html">bayesian/cpt.hpp</a>&gt;</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacebn.html">bn</a> {</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> RepresentMethod&gt;</div><div class="line"><a name="l00027"></a><span class="lineno"><a class="line" href="make__sample_8hpp.html#acac083fe36ef6d802ce4e10097fa487e">   27</a></span>&#160;cpt::condition_type <a class="code" href="make__sample_8hpp.html#acac083fe36ef6d802ce4e10097fa487e">make_sample</a>(<a class="code" href="classbn_1_1network.html">network&lt;RepresentMethod&gt;</a> <span class="keyword">const</span>&amp; g, <a class="code" href="classbn_1_1cpt__manager.html">cpt_manager</a> <span class="keyword">const</span>&amp; cpts, std::vector&lt;component::node_ptr&gt; <span class="keyword">const</span>&amp; sorted_nodes)</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;{</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <span class="comment">// TODO: Policy</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    std::random_device seed_gen;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    std::mt19937 engine(seed_gen());</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    cpt::condition_type sample;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    <span class="keywordflow">for</span>(<span class="keyword">auto</span> it = sorted_nodes.crbegin(); it != sorted_nodes.crend(); ++it)</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    {</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        <span class="keyword">auto</span> <span class="keyword">const</span> probabilities = cpts.<a class="code" href="classbn_1_1cpt__manager.html#a14f03f543695c769641ba4d2ed46761e">at</a>(*it).<a class="code" href="classbn_1_1cpt.html#ab561a7d4b7aee7b6b674695bf5212780">at</a>(sample);</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;        std::discrete_distribution&lt;std::size_t&gt; distribution(</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;            probabilities.cbegin(), probabilities.cend());</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;        sample[(*it)-&gt;get()] = distribution(engine);</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    }</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <span class="keywordflow">return</span> sample;</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;}</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;} <span class="comment">// namespace bn</span></div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="preprocessor">#endif // BAYESIAN_NETWORKS_MAKE_SAMPLE_HPP</span></div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div><div class="ttc" id="namespacebn_html"><div class="ttname"><a href="namespacebn.html">bn</a></div><div class="ttdef"><b>Definition:</b> algorithm.hpp:16</div></div>
<div class="ttc" id="cpt_8hpp_html"><div class="ttname"><a href="cpt_8hpp.html">cpt.hpp</a></div><div class="ttdoc">A wrapper class of bn::matrix provides access methods to the CPT (Conditional Probability Table)...</div></div>
<div class="ttc" id="classbn_1_1network_html"><div class="ttname"><a href="classbn_1_1network.html">bn::network</a></div><div class="ttdoc">Provide a functions for each graph representing class. </div><div class="ttdef"><b>Definition:</b> network.hpp:22</div></div>
<div class="ttc" id="network_8hpp_html"><div class="ttname"><a href="network_8hpp.html">network.hpp</a></div><div class="ttdoc">Provide a functions for each graph representing class. </div></div>
<div class="ttc" id="classbn_1_1cpt__manager_html_a14f03f543695c769641ba4d2ed46761e"><div class="ttname"><a href="classbn_1_1cpt__manager.html#a14f03f543695c769641ba4d2ed46761e">bn::cpt_manager::at</a></div><div class="ttdeci">cpt_type &amp; at(node_type const &amp;node)</div><div class="ttdoc">CPT access. </div><div class="ttdef"><b>Definition:</b> cpt.hpp:319</div></div>
<div class="ttc" id="make__sample_8hpp_html_acac083fe36ef6d802ce4e10097fa487e"><div class="ttname"><a href="make__sample_8hpp.html#acac083fe36ef6d802ce4e10097fa487e">bn::make_sample</a></div><div class="ttdeci">cpt::condition_type make_sample(network&lt; RepresentMethod &gt; const &amp;g, cpt_manager const &amp;cpts, std::vector&lt; component::node_ptr &gt; const &amp;sorted_nodes)</div><div class="ttdoc">Perform topological sort for given graph (however, a reversed series can be obtain). </div><div class="ttdef"><b>Definition:</b> make_sample.hpp:27</div></div>
<div class="ttc" id="classbn_1_1cpt__manager_html"><div class="ttname"><a href="classbn_1_1cpt__manager.html">bn::cpt_manager</a></div><div class="ttdoc">A manager class of some CPTs corresponding to each nodes. </div><div class="ttdef"><b>Definition:</b> cpt.hpp:237</div></div>
<div class="ttc" id="classbn_1_1cpt_html_ab561a7d4b7aee7b6b674695bf5212780"><div class="ttname"><a href="classbn_1_1cpt.html#ab561a7d4b7aee7b6b674695bf5212780">bn::cpt::at</a></div><div class="ttdeci">matrix_type::element_type &amp; at(condition_type const &amp;condition)</div><div class="ttdoc">Access to probability list by condition r.v. list. </div><div class="ttdef"><b>Definition:</b> cpt.hpp:97</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>
